function menuArranagement(data) {
  const resArr = [];

  data.map((item) => {
    if (item.menuParentId === 0) {
      resArr.push({
        ...item,
        children: [],
      });
    } else {
      _dfs(resArr, item);
    }
  });

  return resArr;
}

function _dfs(resArr, data) {
  if (!resArr.length) return;
  if (!data.menuParentId) return;
  if (!data.id) return;
  resArr.map((item) => {
    if (item.id === data.menuParentId) {
      item.children.push({
        ...data,
        children: [],
      });
    } else {
      if (item.children.length) _dfs(item, data);
    }
  });
}

export default menuArranagement;
